
import javax.swing.*;
import java.awt.event.*;
import java.net.*;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class LoginPanel extends JPanel implements ActionListener {

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	
	protected JLabel username, password;
	protected JLabel forgotPassword;
	protected JButton bLogin;
	protected JTextField tfUsername;
	protected JPasswordField tfPassword;
    SIPTalkUI sipTalkUI;
    	
	public LoginPanel(SIPTalkUI sipTalkUI) {
		super();
		this.sipTalkUI = sipTalkUI;
		initGUI();
	}

	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout(this);
			this.setLayout(thisLayout);
			this.setPreferredSize(new java.awt.Dimension(300, 240));
			{
				username = new JLabel();
				username.setText("Username");
			}
			{
				password = new JLabel();
				password.setText("Password");
			}
			{
				tfUsername = new JTextField(7);
				tfUsername.setFocusable(true);
			}
			{
				forgotPassword = new JLabel();
				forgotPassword.setText("<html><u>Forgot Password ?</u></html>");
				forgotPassword.setForeground(new java.awt.Color(0,0,255));
				forgotPassword.setName("forgotPassword");
			}
			{
				bLogin = new JButton();
				bLogin.setText("Login");
			}
			{
				tfPassword = new JPasswordField();
			}
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(42, 42)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(bLogin, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE)
				        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED))
				    .addComponent(password, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
				    .addComponent(username, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE))
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(tfPassword, GroupLayout.PREFERRED_SIZE, 102, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 39, Short.MAX_VALUE))
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(tfUsername, GroupLayout.PREFERRED_SIZE, 102, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 39, Short.MAX_VALUE))
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addPreferredGap(tfPassword, forgotPassword, LayoutStyle.ComponentPlacement.INDENT)
				        .addComponent(forgotPassword, GroupLayout.PREFERRED_SIZE, 129, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE)))
				.addContainerGap(62, 62));
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(66, 66)
				.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(username, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
				    .addComponent(tfUsername, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(tfPassword, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(password, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addGap(27)
				.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(bLogin, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(forgotPassword, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addContainerGap(84, 84));

			bLogin.addActionListener(this);
			forgotPassword.addMouseListener(new MouseAdapter() {
				public void mousePressed(MouseEvent me) {
					try {
						if(me.getComponent().getName().equals("forgotPassword")) {
							sipTalkUI.getAppletContext().showDocument(new URL("https://www.spokn.com/cgi-bin/lostpwd.cgi"), "_blank");
						}
					} catch (Exception e) { e.printStackTrace(); }
				}
			});
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void actionPerformed(ActionEvent ae) {
		String eventString = ae.getActionCommand();
		if(eventString.equals("Login")) {
			if(tfUsername.getText().equals("") || tfPassword.getPassword().equals("")) {
				sipTalkUI.errorMessage(true, "Login Failed", "Error");
			} else {
				bLogin.setEnabled(false);
				sipTalkUI.sipTalk.register(tfUsername.getText(), new String(tfPassword.getPassword()));
			}
		} 
	}
}
